package com.ch.common.result;

import lombok.Data;

import java.io.Serializable;

/**
 * 返回实体
 *
 * @author wangchunhui
 * @date 2024/8/15 17:22
 */
@Data
public class Result implements Serializable {

    /**
     * 是否成功
     */
    private boolean success;
    /**
     * 返回码
     */
    private String code;
    /**
     * 返回信息
     */
    private String message;
    /**
     * 总数
     */
    private Long total;
    /**
     * 返回数据
     */
    private Object data;

    public static Result SUCCESS(Object result) {
        return new Result(ResultCode.SUCCESS, result);
    }

    public static Result SUCCESS() {
        return new Result(ResultCode.SUCCESS);
    }

    public Result(ResultCode code, Object data) {
        this.success = code.success;
        this.code = code.code;
        this.message = code.message;
        this.data = data;
    }

    public Result(ResultCode code) {
        this.success = code.success;
        this.code = code.code;
        this.message = code.message;
    }
}
